Skip to content

fix(spring): gate secureLogbookFilter on SecurityFilterChain bean - #2381

Open
arimu1 wants to merge 3 commits into
zalando:mainfrom
arimu1:fix-2369-secure-logbook-filter
Open

arimu1 wants to merge 3 commits into
zalando:mainfrom
arimu1:fix-2369-secure-logbook-filter

Conversation

@arimu1

@arimu1 arimu1 commented Aug 29, 2026 •

Copy link
Copy Markdown

Summary

  • Add @ConditionalOnBean(SecurityFilterChain.class) to the secureLogbookFilter bean registration so the filter is not auto-enabled when spring-security-web is only present transitively on the classpath without an actual security filter chain.
  • Document the two-filter setup precondition on logbook.secure-filter.enabled in configuration metadata and the README (apps that produce 401/403 in the dispatcher must set the property to false).
  • Rewrite SecurityFilterTest to use WebApplicationContextRunner, covering both the presence and absence of a SecurityFilterChain bean.

Fixes #2369

Test plan

  • ./mvnw test in logbook-spring-boot-autoconfigure (99 tests, all passing)
  • SecurityFilterTest verifies secureLogbookFilter is registered when a SecurityFilterChain bean exists
  • SecurityFilterTest verifies secureLogbookFilter is not registered without a SecurityFilterChain bean

@prashantpiyush1111 prashantpiyush1111 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified independently — confirmed the enclosing JakartaSecurityServletFilterConfiguration already has @AutoConfigureAfter(SecurityFilterAutoConfiguration), so the new @ConditionalOnBean(SecurityFilterChain.class) correctly sees Spring Boot's own security autoconfiguration after it's run (avoids the classic ordering pitfall with cross-autoconfig @ConditionalOnBean checks). Also checked that this codebase targets Spring Security 6.x (jakarta.servlet namespace), so gating on SecurityFilterChain doesn't break anyone still on the deprecated WebSecurityConfigurerAdapter style — that API isn't even available in this version range. Both new tests (shouldRegisterSecureLogbookFilterWhenSecurityFilterChainIsPresent / shouldNotRegisterSecureLogbookFilterWithoutSecurityFilterChain) directly cover the regression being fixed. Docs/metadata updates accurately reflect the new gating behavior. No concerns

@kasmarian kasmarian added the bugfix Bug fixes and patches label Sep 14, 2026
@kasmarian

Copy link
Copy Markdown
Collaborator

👍

@kasmarian

Copy link
Copy Markdown
Collaborator

@arimu1 the PR has conflicts now, could you resolve?

Register secureLogbookFilter only when a SecurityFilterChain bean exists,
not merely when spring-security-web is on the classpath. Document the
two-filter precondition on logbook.secure-filter.enabled.

Fixes zalando#2369
@arimu1
arimu1 force-pushed the fix-2369-secure-logbook-filter branch from 7cddcff to 1e24626 Compare September 21, 2026 10:46
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Unsigned Commits Detected

This pull request contains commits that are not cryptographically signed:

  • 1e24626 - fix(spring): gate secureLogbookFilter on SecurityFilterChain bean

Register secureLogbookFilter only when a SecurityFilterChain bean exists,
not merely when spring-security-web is on the classpath. Document the
two-filter precondition on logbook.secure-filter.enabled.

Fixes #2369

Please sign your commits as per our contributors guidelines.

@arimu1

arimu1 commented Sep 21, 2026

Copy link
Copy Markdown
Author

@kasmarian Conflicts are resolved — rebased fix-2369-secure-logbook-filter onto current main (tip 1e246268). The only conflict was in README.md: kept upstream's new predicate/reactive config rows and preserved the SecurityFilterChain / logbook.secure-filter.enabled documentation from this PR. @ConditionalOnBean(SecurityFilterChain.class) on secureLogbookFilter is unchanged.

…Test

Isolated WebApplicationContextRunner must register the wrapper bean that
secureLogbookFilter requires after zalando#2345.
@arimu1

arimu1 commented Sep 21, 2026

Copy link
Copy Markdown
Author

Post-#2345, SecurityFilterTest now registers AsyncOnCompleteListenerWrapper (identity) on the isolated WebApplicationContextRunner so secureLogbookFilter can satisfy its constructor dependency. SecurityFilterTest: 2/2 pass locally (JDK 21).

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Unsigned Commits Detected

This pull request contains commits that are not cryptographically signed:

  • 1e24626 - fix(spring): gate secureLogbookFilter on SecurityFilterChain bean

Register secureLogbookFilter only when a SecurityFilterChain bean exists,
not merely when spring-security-web is on the classpath. Document the
two-filter precondition on logbook.secure-filter.enabled.

Fixes #2369

  • e3203e0 - test(spring): supply AsyncOnCompleteListenerWrapper in SecurityFilterTest

Isolated WebApplicationContextRunner must register the wrapper bean that
secureLogbookFilter requires after #2345.

Please sign your commits as per our contributors guidelines.

@lukasniemeier-zalando

Copy link
Copy Markdown
Member

⚠️ Unsigned Commits Detected

This pull request contains commits that are not cryptographically signed:

  • 1e24626 - fix(spring): gate secureLogbookFilter on SecurityFilterChain bean

Register secureLogbookFilter only when a SecurityFilterChain bean exists, not merely when spring-security-web is on the classpath. Document the two-filter precondition on logbook.secure-filter.enabled.

Fixes #2369

  • e3203e0 - test(spring): supply AsyncOnCompleteListenerWrapper in SecurityFilterTest

Isolated WebApplicationContextRunner must register the wrapper bean that secureLogbookFilter requires after #2345.

Please sign your commits as per our contributors guidelines.

@arimu1 ☝️

markdown-toc rewrites the TOC block to LF. The update-toc job then
tries to commit that result and fails because the PR branch is not on
zalando/logbook. Commit the generated bytes so the check is a no-op.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Unsigned Commits Detected

This pull request contains commits that are not cryptographically signed:

  • 1e24626 - fix(spring): gate secureLogbookFilter on SecurityFilterChain bean

Register secureLogbookFilter only when a SecurityFilterChain bean exists,
not merely when spring-security-web is on the classpath. Document the
two-filter precondition on logbook.secure-filter.enabled.

Fixes #2369

  • e3203e0 - test(spring): supply AsyncOnCompleteListenerWrapper in SecurityFilterTest

Isolated WebApplicationContextRunner must register the wrapper bean that
secureLogbookFilter requires after #2345.

  • 854830e - docs: refresh generated README table of contents

markdown-toc rewrites the TOC block to LF. The update-toc job then
tries to commit that result and fails because the PR branch is not on
zalando/logbook. Commit the generated bytes so the check is a no-op.

Please sign your commits as per our contributors guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fixes and patches

Projects

None yet

4 participants